home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / TERMIN.ASM < prev    next >
Assembly Source File  |  1990-08-16  |  4KB  |  176 lines

  1. ;  Russell Nelson, Clarkson University.  October 20, 1988
  2. ;  Copyright, 1988, 1989, Russell Nelson
  3.  
  4. ;   This program is free software; you can redistribute it and/or modify
  5. ;   it under the terms of the GNU General Public License as published by
  6. ;   the Free Software Foundation, version 1.
  7. ;
  8. ;   This program is distributed in the hope that it will be useful,
  9. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ;   GNU General Public License for more details.
  12. ;
  13. ;   You should have received a copy of the GNU General Public License
  14. ;   along with this program; if not, write to the Free Software
  15. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  
  17.     include    defs.asm
  18.  
  19. code    segment word public
  20.     assume    cs:code, ds:code
  21.  
  22.     org    80h
  23. phd_dioa    label    byte
  24.  
  25.     org    100h
  26. start:
  27.     jmp    start_1
  28.  
  29. int_pkt    macro
  30.     pushf
  31.     cli
  32.     call    their_isr
  33.     endm
  34.  
  35. their_isr    dd    ?
  36. packet_int_no    db    ?,?
  37.  
  38. handle        dw    ?
  39.  
  40. bogus_type    db    1,2,3,4,5,6,7,8        ;totally bogus type code.
  41.  
  42. signature    db    'PKT DRVR',0
  43. signature_len    equ    $-signature
  44.  
  45. flagbyte    db    0
  46. S_OPTION    equ    8
  47.  
  48. no_signature_msg    db    "termin: no packet driver at that address",'$'
  49. usage_msg    db    "usage: termin <packet_int_no>",'$'
  50. ok_msg    db    "termin: terminate completed",'$'
  51.  
  52. usage_error:
  53.     mov    dx,offset usage_msg
  54. error:
  55.     mov    ah,9
  56.     int    21h
  57.     int    20h
  58.  
  59. start_1:
  60.     mov    si,offset phd_dioa+1
  61.     call    skip_blanks        ;end of line?
  62.     cmp    al,CR
  63.     je    usage_error
  64.  
  65. chk_options:
  66.     call   skip_blanks
  67.     cmp    al,'-'            ; any options?
  68.     je    more_opt
  69.     cmp    al,'/'
  70.     jne    no_more_opt
  71. more_opt:
  72.     inc    si            ; skip past option char
  73.     lodsb                ; read next char
  74.     or    al,20h            ; convert to lower case
  75.     cmp    al,'s'
  76.     jne    usage_error
  77.     or    flagbyte,S_OPTION
  78.     jmp    chk_options
  79. no_more_opt:
  80.  
  81.     mov    di,offset packet_int_no
  82.     call    get_number
  83.  
  84.     mov    ah,35h            ;get their packet interrupt.
  85.     mov    al,packet_int_no
  86.     int    21h
  87.     mov    their_isr.offs,bx
  88.     mov    their_isr.segm,es
  89.  
  90.     lea    di,3[bx]
  91.     mov    si,offset signature
  92.     mov    cx,signature_len
  93.     repe    cmpsb
  94.     jne    no_signature_err
  95.  
  96.     push    ds
  97.     mov    ax,1ffh            ;driver_info
  98.     int_pkt
  99.     pop    ds
  100.     call    fatal_error
  101.  
  102.     mov    ah,2            ;access_type
  103.     mov    al,ch            ;their class from driver_info().
  104.     mov    bx,dx            ;their type from driver_info().
  105.     mov    dl,cl            ;their number from driver_info().
  106.     mov    cx,MAX_P_LEN        ;use the max type length.
  107.     mov    si,offset bogus_type
  108.     push    cs            ;es:di -> our receiver.
  109.     pop    es
  110.     mov    di,offset our_recv
  111.     int_pkt
  112.     call    fatal_error
  113.     mov    handle,ax
  114.  
  115.  
  116.     test    flagbyte,S_OPTION
  117.     jz    not_stop
  118.     mov    ah,8            ; f_stop
  119.     int_pkt
  120.     jmp    now_done
  121. not_stop:
  122.  
  123.  
  124.     mov    ah,5            ;terminate the driver.
  125.     mov    bx,handle
  126.     int_pkt
  127.     jnc    now_close
  128.     call    print_error
  129. now_close:
  130.     mov    ah,3            ;release_type
  131.     mov    bx,handle
  132.     int_pkt
  133.     jnc    now_done        ;if ok, we're done.
  134.     cmp    dh,BAD_HANDLE        ;if it succeeded, we'll get a bad handle.
  135.     je    now_done        ;it worked.
  136.     stc
  137.     call    fatal_error
  138.     int    20h
  139. now_done:
  140.         push    cs
  141.         pop     ds
  142.         lea     dx,ok_msg
  143.         mov     ah,9
  144.         int     21h
  145.         int     20h
  146.  
  147.  
  148. our_recv:
  149.     or    ax,ax            ;first or second call?
  150.     jne    our_recv_1        ;second -- we ignore the packet
  151.     push    cs
  152.     pop    es
  153.     mov    di,offset our_buffer
  154. our_recv_1:
  155.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  156.  
  157.  
  158. no_signature_err:
  159.     mov    dx,offset no_signature_msg
  160.     mov    ah,9
  161.     int    21h
  162.     int    20h
  163.  
  164.  
  165.     include    pkterr.asm
  166.     include    getnum.asm
  167.     include    skipblk.asm
  168.     include    getdig.asm
  169.     include    chrout.asm
  170.  
  171. our_buffer    label    byte
  172.  
  173. code    ends
  174.  
  175.     end    start
  176.